package com.hkw.service.impl;

import com.hkw.dao.IClassRoomDao;
import com.hkw.factory.ClassRoomDaoFactory;
import com.hkw.model.ClassRoom;
import com.hkw.service.IClassRoomService;
import com.hkw.utils.PagesUtils;

import java.sql.SQLException;
import java.util.List;

/**
 * IClassRoomService的实现类，调用相关dao接口
 */
public class ClassRoomServiceImpl implements IClassRoomService {
    private IClassRoomDao classRoomDao;
    private PagesUtils pagesUtils;

    public ClassRoomServiceImpl() {
        classRoomDao = ClassRoomDaoFactory.getClassRoomDao();
    }
    public ClassRoomServiceImpl(int nowpage) {
        classRoomDao = ClassRoomDaoFactory.getClassRoomDao();
        try {
            this.pagesUtils = new PagesUtils(classRoomDao.findAllRows(),nowpage);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    public PagesUtils getPagesUtils() {
        return pagesUtils;
    }

    public void setPagesUtils(PagesUtils pagesUtils) {
        this.pagesUtils = pagesUtils;
    }

    @Override
    public List<ClassRoom> list(){
        try {
            return classRoomDao.findAll(pagesUtils);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public int add(ClassRoom classRoom) {
        try {
            return classRoomDao.insertClassRoom(classRoom);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return -1;
    }

    @Override
    public List<ClassRoom> findAllId()  {
        try {
            return classRoomDao.findAllId();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public int delClassRoom(int id) {
        try {
            return classRoomDao.delClassById(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public ClassRoom findClassRoomById(int id) {
        try {
            return classRoomDao.findClassRoomById(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public int updateClassRoom(ClassRoom classRoom) {
        try {
            return classRoomDao.updateClassRoom(classRoom);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return -1;
    }

    @Override
    public List<ClassRoom> findClassRoomByClassRoom(ClassRoom classRoom) {
        try {
            return classRoomDao.findClassRoomByClassRoom(classRoom);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
